import 'package:animated_bottom_navigation_bar/animated_bottom_navigation_bar.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/hover_button_util.dart';
import 'package:enterprise_v6_app/app/modules/home/controller.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';
import 'package:floating_overlay/floating_overlay.dart';

class HomePage extends StatelessWidget {
  HomePage({super.key});

  final controller = Get.put(HomeController());

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: controller.exitReminder,
      child: GetBuilder(builder: (HomeController controller) {
        return FloatingOverlay(
            controller: HoverButtonUtil.slideController,
            floatingChild: SizedBox(
              height: 50.w,
              width: 50.w,
              child: GestureDetector(
                onTap: () {
                  Get.toNamed(AppRoutes.alarmManagement);
                },
                child: SvgPicture.asset(
                  AppImages.icon_slide_info,
                  fit: BoxFit.cover,
                ),
              ),
            ),
            child: Scaffold(
                backgroundColor: AppColors.bg_color_grey,
                body: IndexedStack(
                  index: controller.index.value,
                  children: controller.myTabs,
                ),
                floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
                floatingActionButton: FloatingActionButton(
                  shape: const CircleBorder(),
                  backgroundColor: const Color(0xFF6A5CFF),
                  onPressed: () {
                    Get.toNamed(AppRoutes.reportingHiddenDangersPage);
                  },
                  child: Container(
                    width: 53.w,
                    height: 53.w,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(26.w),
                        gradient: const LinearGradient(
                          begin: Alignment.topCenter,
                          end: Alignment.bottomCenter,
                          colors: [
                            Color(0xFF8A5CFF),
                            Color(0xFF6A5CFF),
                            Color(0xFF5C6DFF),
                          ],
                        )),
                    child: const Icon(
                      Icons.add,
                      color: Colors.white,
                    ),
                  ),
                ),
                bottomNavigationBar: AnimatedBottomNavigationBar.builder(
                  itemCount: 4,
                  activeIndex: controller.index.value,
                  tabBuilder: (int index, bool isActive) {
                    final color = isActive ? const Color(0xFF5C6DFF) : Colors.black;
                    return Column(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SvgPicture.asset(controller.tabIcon[index], colorFilter: ColorFilter.mode(color, BlendMode.srcIn)),
                        const SizedBox(height: 4),
                        Padding(
                          padding: EdgeInsets.symmetric(horizontal: 8.w),
                          child: Text(
                            controller.tabName[index],
                            maxLines: 1,
                            style: TextStyle(color: color, fontSize: 10.sp),
                          ),
                        )
                      ],
                    );
                  },
                  splashSpeedInMilliseconds: 300,
                  notchSmoothness: NotchSmoothness.softEdge,
                  gapLocation: GapLocation.center,
                  // leftCornerRadius: 32,
                  // rightCornerRadius: 32,
                  shadow: const BoxShadow(
                    offset: Offset(0, 0.3),
                    color: Colors.black12,
                    blurRadius: 8,
                    spreadRadius: 0.6,
                  ),
                  onTap: (index) {
                    controller.index.value = index;
                    controller.update();
                  },
                )));
      }),
    );
  }
}
